<template>
  <div class="table_continer">
    <div>
      <!-- 列表 ------------------------------------------------------------------------------------------------------->
      <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column label="序号" width="100">
          <template slot-scope="scope">
            <div>{{ scope.$index + 1 }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="purchaseNum" label="出库单号" min-width="180">
          <template slot-scope="scope">
            <el-link @click="handledetailed(scope.row.deliverId)" type="primary">
              {{ scope.row.deliverNum || '-' }}
            </el-link>
          </template>
        </el-table-column>
        <el-table-column prop="type" label="出库类型" min-width="160">
          <template slot-scope="scope">
            <div>{{ ['工单出库', '盘亏出库', '借调出库', '其他出库'][scope.row.type] }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="auditStatus" label="出库状态" min-width="160">
          <template slot-scope="scope">
            <dict-tag :options="TheDeliveryStatus" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" show-overflow-tooltip min-width="180">
          <template slot-scope="{row}">
            {{ row.remark || '-' }}
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" min-width="180" />
        <el-table-column label="创建部门" align="center" min-width="180" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.deptName || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="center" min-width="180" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.createBy || '-' }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="confirmTime" label="确认时间" />
        <el-table-column prop="confirmBy" label="确认人" /> -->
        <el-table-column fixed="right" label="操作" width="320">
          <template slot-scope="{row}">
            <div align="left">
              <!-- 此处ID字段特别注意 ------------------------------------------------------------------------------------>
              <el-button :disabled="row.status != 0 || row.createBy == '系统'" v-hasPermi="['delivery_left_update']"
                icon="el-icon-edit" type="primary" size="small" @click="handleEdit(row.deliverId)">编辑
              </el-button>
              <el-button :disabled="row.status != 0 || row.createBy == '系统'" v-hasPermi="['delivery_left_delete']"
                icon="el-icon-delete" type="danger" size="small" @click="handleDelete(row.deliverId)">删除
              </el-button>
              <el-button :disabled="row.status != 0" v-hasPermi="['delivery_left_confirm']" icon="el-icon-finished"
                type="success" size="small" @click="handleAlter(row.deliverId)">确认出库
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- ------------------------------------------------------------------------------------------------------------>
    </div>
    <!-- --------------------------------分页器---------------------------------------------------------- -->
    <div class="table_continer_pagination">
      <el-pagination background :current-page="pageParams.pageNum" :page-sizes="[10, 20, 50, 100]"
        :page-size="pageParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
        @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
  </div>
</template>

<script>
/** 拉取列表远程方法 ---------------------------------------------------------------------------------------------------------- */
import { list, deletelist, resubmitPut } from '@/api/deviceConsumable/delivery'
/** ------------------------------------------------------------------------------------------------------------------------- */
import { pageCount } from '@/utils/pagination'
/** 查询参数处理 ---------------------------------------------------------------------------------------------------------- */
function processQueryParams (queryParams, pageParams) {
  const params = Object.assign({}, queryParams, pageParams)
  return params
}
/** ------------------------------------------------------------------------------------------------------------------------- */

export default {
  name: 'PaginationTable',
  data () {
    return {
      pagination: {
        total: 1,
        pageCount: 1
      },
      pageParams: {
        pageNum: 1,
        pageSize: 10,
        /** 列表默认排序字段 ---------------------------------------------------------------------------------------------------------- */
        orderByColumn: 'deliverId',
        /** ------------------------------------------------------------------------------------------------------------------------- */
        isAsc: 'desc',
      },
      queryParams: null,
      tableData: [],
    }
  },
  mounted () {
    this.refreshList()
  },
  methods: {
    refreshList () {
      const params = processQueryParams(this.queryParams, this.pageParams)
      console.log('查询参数', params);
      // --------consolelog('查询参数', params)
      list(params).then((res) => {
        console.log('获取列表', res);
        // --------consolelog('获取列表', res)
        this.pagination.total = res.total
        this.pagination.pageCount = pageCount(this.pagination.total, this.pageParams.pageSize)
        this.tableData = res.data
      })
    },
    handleQuery (queryParams) {
      this.queryParams = queryParams
      this.refreshList()
    },
    handleSizeChange (value) {
      this.pageParams.pageSize = value
      this.refreshList()
    },
    handleCurrentChange (value) {
      this.pageParams.pageNum = value
      this.refreshList()
    },
    handleSelectionChange (value) {
      // console.log('handleSelectionChange', value)
    },
    // 点击编号跳转采购单详情-----------------------------
    handledetailed (id) {
      this.$emit('click_create_reception', id)
    },
    /** 传递点击【编辑】事件 ---------------------------------------------------------------------------------------------------------- */
    handleEdit (id) {
      this.$emit('click_edit', id)
    },
    // 列表删除事件------------------------------------------------------------------------------------------------------------------
    handleDelete (id) {
      this.$confirm('此操作将删除此出库单号, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deletelist(id).then(() => {
          this.$message({
            type: 'success',
            message: '已删除此出库单号!'
          });
          this.refreshList()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 确定出库事件----------------------------------
    handleAlter (deliverId) {
      this.$confirm('此操作将出库此单号！, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        resubmitPut({ deliverId }).then(() => {
          this.$message({
            type: 'success',
            message: '确认出库成功！'
          });
          this.refreshList()
        })
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.table_continer {
  border-radius: 5px;

  &_pagination {
    background-color: white;
    padding: 10px;
    margin-bottom: 10px;
  }
}
</style>
